package com.cskaoyan.controller.backStage;

import com.cskaoyan.model.bo.BaseParamBO;
import com.cskaoyan.model.vo.AddressDataVO;
import com.cskaoyan.model.vo.BaseRespVO;
import com.cskaoyan.service.AddressService;
import com.cskaoyan.util.StringUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：huzhouming
 * @description：用户管理收货地址部分
 * @date ：2022/5/5 22:46
 */
@RestController
@RequestMapping("admin/address")
public class AddressController {
    @Autowired
    AddressService addressService;

    @RequiresPermissions("admin:address:list")
    @GetMapping("list")
    public BaseRespVO list(BaseParamBO baseParamBO, String userId, String name) {
        AddressDataVO addressDataVO;
        try {
            Integer i;
            if (StringUtil.isEmpty(userId)) {
                i = null;
            } else {
                i = Integer.parseInt(userId);
            }
            addressDataVO = addressService.query(baseParamBO, i, name);
        } catch (Exception e) {
            return BaseRespVO.parameterError("参数值不对");
        }
        return BaseRespVO.ok(addressDataVO);
    }
}
